package com.jk.vehicle.core.entity;

import java.util.List;

/**
 * 通用分页返回体
 *
 * @author KangJian
 * @date 2018/6/15
 */
public class TableResultResponse<T> {

    /**
     * 状态码
     */
    private int status = 200;
    /**
     * 提示信息
     */
    private String message;
    /**
     * 数据内容
     */
    TableData<T> data;

    public TableResultResponse(int status, String message) {
        this.status = status;
        this.message = message;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }


    public TableResultResponse(long total, List<T> rows) {
        this.data = new TableData<T>(total, rows);
    }

    public TableResultResponse() {
        this.data = new TableData<T>();
    }

    /**
     * 设置总条目数
     * @param total
     * @return
     */
    TableResultResponse<T> total(int total) {
        this.data.setTotal(total);
        return this;
    }

    /**
     * 设置数据内容
     * @param rows
     * @return
     */
    TableResultResponse<T> total(List<T> rows) {
        this.data.setRows(rows);
        return this;
    }

    public TableData<T> getData() {
        return data;
    }

    public void setData(TableData<T> data) {
        this.data = data;
    }

    /**
     * 表数据体
     * @param <T>
     */
    public class TableData<T> {
        /**
         * 总记录数
         */
        long total;
        /**
         * 总行数
         */
        List<T> rows;

        public TableData(long total, List<T> rows) {
            this.total = total;
            this.rows = rows;
        }

        public TableData() {
        }

        public long getTotal() {
            return total;
        }

        public void setTotal(long total) {
            this.total = total;
        }

        public List<T> getRows() {
            return rows;
        }

        public void setRows(List<T> rows) {
            this.rows = rows;
        }

    }
}
